Skip to content

Add bigNumberStrings option for forcing BIGINTs as strings (always) #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

imkira
Copy link
Collaborator

@imkira imkira commented Apr 1, 2013

Hi there. It is just as the title mentions.

I have followed #207 attentively, but in one
app I am developing we use lots of BIGINT columns.
I am aware that using supportBigNumbers:true handles big numbers
in case hey cannot be accurately represented returning them as strings.
In our app, it is easiest to assume that they will be always strings,
and it is quite a pain and error-prone for us to convert all BIGINTs
to strings, so we added this option.

I would be happy if you could push these commits in your repo.
Thank you in advance.

@tomasikp
Copy link
Contributor

tomasikp commented Apr 1, 2013

I like this. Recently updated to Alpha 7 to get the pooling functionality only to find that my iOS app wasn't playing nicely with my api anymore. BIGINTs used to be strings only. Why do we need to have two different types going on?

@tomasikp
Copy link
Contributor

tomasikp commented Apr 1, 2013

@dresende also, whatever you do decide on doing. The Readme only mentions bigints being typecast to strings.

@imkira
Copy link
Collaborator Author

imkira commented Apr 2, 2013

Just as a side note, I was unsure about the insertId that can be retrieved upon executing an INSERT query.

https://github.com/felixge/node-mysql/blob/master/lib/protocol/packets/OkPacket.js

Apparently in C/C++ bindings mysql treats this field as BIGINT (LONGLONG), whatever the table's original numeric-type field is.
When I was digging node-mysql's source I noticed Parser.prototype.parseLengthCodedNumber checks whether the required number of bits exceeds Number's precision (> 2^53) and returns as string only if so.
I was unsure about whether I should extend the patch to this, but I think the protocol does not allow us to retrieve the "type" of insertId: we just know that it is a length-encoded number that can be up to 64 bits, am I correct in this assumption?

@tomasikp
Copy link
Contributor

tomasikp commented Apr 2, 2013

looks like they discussed this in #380 and pulled in the code you mentioned in #382

@felixge
Copy link
Collaborator

felixge commented Apr 3, 2013

Looks like @tomasikp is right, closing this for now - but please let me know if I missed something so I can re-open the issue.

@imkira thanks for finding this problem and providing a solution to it as well!

@felixge felixge closed this Apr 3, 2013
@tomasikp
Copy link
Contributor

tomasikp commented Apr 3, 2013

@felixge I think this may have been closed pre-maturely. Although the insertId case has been fleshed out, the main topic of this pull request was the ability to have bigints be returned exclusively as strings.

@dresende
Copy link
Collaborator

dresende commented Apr 3, 2013

I tend to agree with @tomasikp, this option might be good for people knowing about bigint problems and wanting to always have these numbers as strings.

@tomasikp
Copy link
Contributor

tomasikp commented Apr 4, 2013

#414 Apparently DECIMAL was also changed to the quasi-type (Number/String). I think we should definitely have an option to have all of these remain strings if possible

@imkira
Copy link
Collaborator Author

imkira commented Apr 4, 2013

Like @dresende and @tomasikp said, the point of this commit was not about the insertId but about adding an option for allowing big numbers to be always returned as strings, rather than being a "Number or String"-volatile type. The current behavior is still allowed, and this new behavior is also possible, respectively, by not using or using bigNumberStrings option.
Also, since I screwed up and removed DECIMAL from the list of types that should be handled as big numbers, I am attaching a new pull-request.

@imkira
Copy link
Collaborator Author

imkira commented Apr 4, 2013

#446

dveeden pushed a commit to dveeden/mysql that referenced this pull request Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants